import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by dell on 2017/8/9.
 */
public class TomcatUse1 {
    public static void main(String[] args) throws IOException {
        try {
            URL url = new URL("http://api.avatardata.cn/Weather/Query?key=4a417aba564b4f6a82ba71ab864a3035&cityname=%E6%88%90%E9%83%BD");
            URLConnection uc = url.openConnection();
            HttpURLConnection httpURLConnection = (HttpURLConnection) uc;


            int responseCode = httpURLConnection.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                System.err.println("成功");
                InputStream is = httpURLConnection.getInputStream();
                InputStreamReader isr = new InputStreamReader(is, "UTF-8");
                BufferedReader br = new BufferedReader(isr);
                String str;
                while ((str = br.readLine()) != null) {
                    System.out.println(str);
                }
                br.close();
            } else {
                System.out.println("失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
